package com.zjd.swing.browser;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * @Description: 控制器面板
 * @Author: sobey
 * @Email: sobey178@163.com
 * @Date: 2022/3/27 22:35
 */
public class MyBrowserControllerJPanel extends JPanel {
    public MyBrowserControllerJPanel() {
        super();
        GridBagLayout gridBagLayout = new GridBagLayout();
        setLayout(gridBagLayout);
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.anchor = GridBagConstraints.NORTHEAST;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.insets = new Insets(2,2,2,2);
        constraints.gridwidth = 1;
        for (int i=1;i<=7;i++){
            JLabel label = new JLabel("---->列-------------->"+i);
//            JTextField textField=new JTextField("列"+i);
//            JButton button = new JButton("列"+i);
            Component headCom = label;
            if (i == 7) {
                constraints.gridwidth = GridBagConstraints.REMAINDER;
            }
            gridBagLayout.setConstraints(headCom,constraints);
            add(headCom);
        }
//        constraints.gridy = 2;
        for (int i=1;i<=50;i++){
            if (i%5 == 0) {
                constraints.gridwidth = GridBagConstraints.REMAINDER;
            }
            else if(i%2 == 0){
                constraints.gridwidth = 1;
            }
            else {
                constraints.gridwidth = 1;
            }
            JButton button = new JButton("百度搜索"+i);
            button.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    super.mouseClicked(e);
                    new MyBrowserJFrame("百度搜索","https://www.baidu.com");
                }
            });
            gridBagLayout.setConstraints(button,constraints);
            add(button);
        }
    }
}
